package com.newgrand.annexcommon.utils;

import com.newgrand.annexcommon.model.DynamicDataSourceEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author ：minyang
 * @date ：Created in 2019/9/7 17:42
 */
public class DbUtil {

    private final static Logger logger = LoggerFactory.getLogger(DbUtil.class);

    public static boolean checkConnection(String url, String userName, String passWord) {
        boolean connectSuccess = true;
        try {
            DriverManager.setLoginTimeout(10);
            Connection conn = DriverManager.getConnection(url, userName, passWord);
            conn.close();
        } catch (SQLException e) {
            logger.error("connection err,sqlstate: {},message: {} ", e.getSQLState(), e.getMessage());
            connectSuccess = false;
        }
        return connectSuccess;
    }
}
